package com.hubox.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.hubox.customvalidator.CustomCheck;
import com.hubox.customvalidator.Mode;
import com.hubox.ValidationGroups;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
public class UserVo {
    //当groups为默认值时才校验
    @NotBlank(message = "username must not be blank!")
    private String username;

    //仅create接口校验
    @NotBlank(message = "password must not be blank!",groups={ValidationGroups.Create.class})
    private String password;

    //仅update接口校验
    @NotBlank(message = "nickname must not be blank!",groups={ValidationGroups.Update.class})
    private String nickname;

    //create接口和update接口都需要校验age参数
    @Min(value = 0,message = "age must more than 0!", groups = {ValidationGroups.Create.class,ValidationGroups.Update.class})
    private Integer age;

    //使用组合接口进行分组校验
    @NotBlank(message = "gender must not be blank!",groups={ValidationGroups.Common.class})
    private String gender;

    //自定义注解
    @CustomCheck(mode = Mode.UPPER, message = "upperBranch should be SZ or BJ!")
    private String upperBranch;

    //自定义注解，仅create接口校验
    @CustomCheck(mode = Mode.LOWER, message = "lowerBranch should be sz or bj!",groups = {ValidationGroups.Create.class})
    private String lowerBranch;

    @DateTimeFormat(iso= DateTimeFormat.ISO.DATE)
    @JsonFormat(pattern = "dd/MM/yyyy")
    private LocalDate registerDate;

    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss")
    private LocalDateTime lastLoginTime;
}
